﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

// Custom Namespaces
using Prototype;

namespace Prototype.Dialogs
{
    public partial class Preferences : Form
    {
        private string STARTUP = "STARTUP";

        public Preferences()
        {
            InitializeComponent();

            // Select "General" node by default
            PreferencesView.SelectedNode = PreferencesView.Nodes[0].Nodes[0];

            // Hide all Tabs
            HideAllTabs();
            
            // Load Preferences from Ini file
            loadPreferences();
        }

        #region Content Display
        // Selection has been made on Preverences View
        private void PreferencesView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // Display Preferences via selected category
            DisplayPreferences(e.Node.Text);
        }

        // Display Preferences for selected category
        private void DisplayPreferences(string category)
        {
            HideAllTabs();

            // If General or Startup
            if (category == "General" || category == "Startup")
            {
                tabControl1.TabPages[0].Show();
            }

            // If Folders
            if (category == "Folders")
            {
                tabControl1.TabPages[1].Show();
            }
        }

        // Hides All Tabs
        private void HideAllTabs()
        {
            tabControl1.TabPages[0].Hide();
            tabControl1.TabPages[1].Hide();
        }
        #endregion

        #region Preferences (IniFile)
        // Save Preferences
        private void SavePreferences()
        {
            // Initiate Ini File Class
            IniFile Preferences = new IniFile();

            // Write to Ini File
            Preferences.IniWriteValue(STARTUP, "load_splash", ckbxShowSplashPage.Checked.ToString());
        }

        // Load Preferences
        private void loadPreferences()
        {
            // Initiate Ini File Class
            IniFile Preferences = new IniFile();

            // Write to Ini File
            ckbxShowSplashPage.Checked = Convert.ToBoolean(Preferences.IniReadValue(STARTUP, "load_splash"));
        }
        #endregion

        #region Buttons
        // Close Form
        private void CancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        // Accept Button
        private void AcceptButton_Click(object sender, EventArgs e)
        {
            SavePreferences();
            this.Close();
        }
        #endregion
    }
}
